package com.spring.demo.init.rmi;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.remoting.rmi.RmiProxyFactoryBean;

import com.spring.demo.core.rmi.IRMIUserService;

/**
 * rmi client config
 * 
 * @author sean
 *
 */
@Configuration
@ComponentScan({ "com.spring.demo.rmi.client" })
@PropertySource({ "classpath:rmi/rmi-client.properties" })
public class RmiClientConfig {

	/**
	 * rmi 服务主机
	 */
	public static final String RMI_SERVICE_URL = "rmiServiceUrl";

	@Autowired
	private Environment envir;

	@Bean
	public RmiProxyFactoryBean rmiProxyFactoryBean() {

		RmiProxyFactoryBean rmiProxyFactoryBean = new RmiProxyFactoryBean();
		rmiProxyFactoryBean.setServiceInterface(IRMIUserService.class);
		rmiProxyFactoryBean.setRefreshStubOnConnectFailure(true);
		rmiProxyFactoryBean.setServiceUrl(envir
				.getProperty(RmiClientConfig.RMI_SERVICE_URL));

		return rmiProxyFactoryBean;
	}
}
